<?php
if(isset ($_POST['save_picture']))
{
	$user_id= $_SESSION['tcADMINID'];
    $title = $_POST['title'];
	$desc = $_POST['desc'];
	$tdate = $_POST['tdate'];
	$name = $_POST['name'];
	
	$path = "../gallery/";
	$thumb_path = "../gallery/thumb/";
	if($_FILES['pic']['type'] == "image/gif" || $_FILES['pic']['type'] == "image/pjpeg" || $_FILES['pic']['type'] == "image/jpeg")
	{
		$fname = $user_id.'pic'.time();
    	if($_FILES['pic']['type'] == "image/gif") $filetype = ".gif";
		else  $filetype = ".jpg";
		
		$newupload = $_FILES['pic']['tmp_name']; 
			if($filetype==".gif") $src = imagecreatefromgif($newupload);
			else $src = imagecreatefromjpeg($newupload);
			list($width,$height)=getimagesize($newupload);
			if($width > 800)
			{
				$newwidth=800;
				$w=$width/$newwidth;
				$newheight=$height/$w;
			}
			if($height > 600)
			{
				$newheight = 600;	
				$h = $height/$newheight;
				$newwidth = $width/$h;
			}
			if($width <= 800) $newwidth = $width;
			if($height <= 600) $newheight = $height;
			
			$tmp=imagecreatetruecolor($newwidth,$newheight);
			imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
			$photo1  = $fname.$filetype;
			$filename = $path.$photo1; 
			if($filetype==".gif") imagegif($tmp,$filename,100);
			else imagejpeg($tmp,$filename,100);
			imagedestroy($src);
			imagedestroy($tmp);
			
			//$path = $thumb_path;
			$newupload = $_FILES['pic']['tmp_name']; 
			if($filetype==".gif") $src = imagecreatefromgif($newupload);
			else $src = imagecreatefromjpeg($newupload);
			list($width,$height)=getimagesize($newupload);
			$newwidth=150;
				
				$w=$width/$newwidth;
				$newheight=$height/$w;
			$tmp=imagecreatetruecolor($newwidth,$newheight);
			imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
			$photo1  = $fname.$filetype;
			$filename = $thumb_path.$photo1; 
			if($filetype==".gif") imagegif($tmp,$filename,100);
			else imagejpeg($tmp,$filename,100);
			imagedestroy($src);
			imagedestroy($tmp);
			
			mysql_query("insert into picture (UserId, Title, Description, DateTaken, Name, Image, CreatedDate, Status) values ('$user_id', '$title', '$desc', '$tdate', '$name', '$photo1', now(), 1)");
			
			$e = mysql_fetch_array(mysql_query("select * from users where Id='$user_id'"));
			$email = "support@alicespringsonline.com";;
			$from = "From: <$email>";
				$to = $TC_Email;
				$subject = "New Picture Uploaded in alicespringsonline.com";
				$message = "
Hello,

A new picture ".$title." has been submitted at alicespringsonline.com

Submited By:".$e['FirstName']." ".$e['LastName']."

Please click on link below to login and approve picture. 

http://alicespringsonline.com/tcadmin/
";
			
				mail($to, $subject, $message, $from);
				
			//header("location:index.php?tc=picture_add&_e=2");
			echo "<script>window.location='index.php?tc=picture_add&_e=2'</script>";
	}
	else
	{
		//header("location:index.php?tc=picture_add&_e=1");	
		echo "<script>window.location='index.php?tc=picture_add&_e=1'</script>";
	}	
}
?>